package com.victor.controller.app;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.victor.entity.step.JMInfo;
import com.victor.service.My_JmService;
import com.victor.service.MyselfService;
import com.victor.utils.CodeUtil;
import com.victor.utils.Msg;

/**
 * 我的 --- 加盟
 * 
 * @author qinyuquan
 *
 */
@RestController
@RequestMapping("/jm")
public class Myself_jm_C {
	
	@Autowired
	private My_JmService my_JmService;

	@RequestMapping("/submitJM")
	public Msg submitJionMessage(@RequestBody JMInfo jmInfo) {
		if (jmInfo == null || jmInfo.getUsername() == null || jmInfo.getUserid() == null
				|| jmInfo.getZongclass() == null || jmInfo.getPhone().length()==0) {
			return Msg.fail("参数错误");
		}
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式
		jmInfo.setDate(df.format(new Date()));// new Date()为获取当前系统时间
			boolean b = my_JmService.submitJMInfo(jmInfo);// 提交加盟信息
			if (!b) {
				return Msg.fail("添加失败");
			}
			if (jmInfo.getPhotos() != null) {
				for (int i = 0; i < jmInfo.getPhotos().size(); i++) {
					jmInfo.getPhotos().get(i).setInfoid(String.valueOf(jmInfo.getId()));
					boolean photos = my_JmService.submitPhoto(jmInfo.getPhotos().get(i));// 提交加盟加盟营业执照，经营许可证，环境等相关照片
																							// ，身份证，以及身份证正反面等
					if (!photos) {
						return Msg.fail("添加图片失败");
					}
				}
			}
		return Msg.success();
	}
}
